<?php

class content_model extends FlexiGrid_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function getmulti(){
//        $this->db
//        ->on_duplicate_update("a",array("v"),array("name"=>"asdasd","v"=>time()));
//        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
//        if($count>1) return true;
//        return false;
        
        $where=array("Lock"=>1);
        $query=$this->db
                ->where($where)
                //->or_where("ID <","21`'",true,"open")
                //->where("ID >",22,true,"close")    
                ->bracket('open')
                ->where("ID <",21)
                ->or_where("ID >",22)
                ->bracket('close')
                ->get('adp_settings'); 
        $this->output->enable_profiler(TRUE);
        return $query->result();
        
//$this->db->where('groups_members.group_id', $this->session->userdata('group_id'));
//$this->db->where('groups_members.join_date <=', $end_date);
//$this->db->bracket('open');
//$this->db->or_where('groups_members.resign_date', NULL);
//$this->db->where('groups_members.resign_date >=', $start_date);
//$this->db->bracket('close');
//$this->db->join('groups_members', 'groups_members.member_id = members.user_id');
//$this->db->order_by('last_name', 'asc');
//$query = $this->db->get('members'); 
        
    }
    function get($ID){
        $where=array("ID"=>$ID);
        $query=$this->db->get_where('tbl_content', $where); 
        return $query->result();
    }
    
    function insert($params){
        $this->db->set('Insert', 'NOW()', FALSE);
        $this->db->insert('tbl_content', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('Delete', 'NOW()', FALSE);
        $where=array("ID"=>$ID);
        $this->db->where($where);
        $this->db->update('tbl_content'); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('Delete', 'NULL', FALSE);
        $where=array("ID"=>$ID);
        $this->db->where($where);
        $this->db->update('tbl_content'); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('Update', 'NOW()', FALSE);
        $this->db->where('ID', $ID);
        $this->db->update('tbl_content', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function FlexiGridData(){
        $configs["strQuery"]="
            SELECT SQL_CALC_FOUND_ROWS `tbl_content`.*
            FROM `tbl_content`
            ";
        $configs["strWhere"]="
            WHERE True
            ";
        if(isset($_SESSION["ADP"]["JQX-DEL-CONTENT"]) && $_SESSION["ADP"]["JQX-DEL-CONTENT"]==0){
            $configs["strWhere"].=" AND `tbl_content`.`Delete` IS NULL";
        }elseif(isset($_SESSION["ADP"]["JQX-DEL-CONTENT"]) && $_SESSION["ADP"]["JQX-DEL-CONTENT"]==-1){
            $configs["strWhere"].=" AND `tbl_content`.`Delete` IS NOT NULL";
        }
        $configs["strOrderBy"]=" ORDER BY `Insert` DESC";
        $configs["fields"]=array(
            "ID"=>"ID",
            );
        $configs["filterfields"]=array(
            "Title"=>"Title",
            "Alias"=>"Alias"
        );
        $this->init($configs);
        return $this->Binding();
    }
    function FlexiGridData_Tour(){
        $configs["strQuery"]="
            SELECT SQL_CALC_FOUND_ROWS `tbl_content`.*
            FROM `tbl_content`
            ";
        $configs["strWhere"]="
            WHERE Type='Tour'
            ";
        if(isset($_SESSION["ADP"]["JQX-DEL-TOUR"]) && $_SESSION["ADP"]["JQX-DEL-TOUR"]==0){
            $configs["strWhere"].=" AND `tbl_content`.`Delete` IS NULL";
        }elseif(isset($_SESSION["ADP"]["JQX-DEL-TOUR"]) && $_SESSION["ADP"]["JQX-DEL-TOUR"]==-1){
            $configs["strWhere"].=" AND `tbl_content`.`Delete` IS NOT NULL";
        }
        $configs["strOrderBy"]=" ORDER BY `Insert` DESC";
        $configs["fields"]=array(
            
            );
        $configs["filterfields"]=array(
            "Title","Alias"
        );
        $this->init($configs);
        return $this->Binding();
    }
}
?>
